package com.zerosky.crm.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.zerosky.crm.dao.InformationDAO;
import com.zerosky.crm.po.Information;
import com.zerosky.crm.service.InformationService;
import com.zerosky.crm.util.PageInfo;

@Service(value="informationService")
public class InformationServiceImpl implements InformationService {
	@Autowired
	private InformationDAO InformationDao;

	public List<Information> getInformationList(Map map) {
		return InformationDao.getInformationList(map);

	}

	/**
	 * 分页查询信息
	 */
	@SuppressWarnings("unchecked")
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public PageInfo<Information> getPageInfoList(Map map, PageInfo<Information> page) {
		int begin = ((page.getPageNo() - 1) * page.getPageSize());
		int pageSize = page.getPageSize();
		// 写入数据
		map.put("pageNo", begin);
		map.put("pageSize", pageSize);
		List<Information> list = InformationDao.getInformationList(map);
		page.setList(list);
		int count = InformationDao.countInformation(map);// 获取总记录
		page.setPageCount(count);
		return page;
	}

	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public Integer saveOrUpdate(Information Information, String operation) {
		if (operation.equals("新增")) {
			return InformationDao.saveInformation(Information);
		} else if (operation.equals("修改")) {
			return InformationDao.updateInformation(Information);
		}
		return 0;

	}

	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public Integer deleteInformation(String Information_id) {
		return InformationDao.deleteInformationById(Information_id);

	}

	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public Information getInformationById(String InformationId) {
		return InformationDao.getInformationById(InformationId);

	}

}
